# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("//javatests/com/google/android/libraries/mobiledatadownload:test_defs.bzl", "mdd_local_test")
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
load("//java/com/google/android/libraries/mobiledatadownload/file/common/testing:build_defs.bzl", "android_test_multi_api")

package(
    default_applicable_licenses = ["//:license"],
    default_visibility = ["//:__subpackages__"],
    licenses = ["notice"],
)

mdd_local_test(
    name = "MobileDataDownloadManagerTest",
    srcs = ["MobileDataDownloadManagerTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.MobileDataDownloadManagerTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:DownloadException",
        "//java/com/google/android/libraries/mobiledatadownload:ExperimentationConfig",
        "//java/com/google/android/libraries/mobiledatadownload:FileSource",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/common/testing",
        "//java/com/google/android/libraries/mobiledatadownload/file/common/testing:fake_file_backend",
        "//java/com/google/android/libraries/mobiledatadownload/internal:ExpirationHandler",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:MddExceptions",
        "//java/com/google/android/libraries/mobiledatadownload/internal:Migrations",
        "//java/com/google/android/libraries/mobiledatadownload/internal:MobileDataDownloadManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFileManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/collect",
        "//java/com/google/android/libraries/mobiledatadownload/internal/experimentation:DownloadStageManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal/experimentation:NoOpDownloadStageManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:FileGroupStatsLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:LoggingStateStore",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:NetworkLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:SharedPreferencesLoggingState",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:StorageLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:FileGroupUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:SharedPreferencesUtil",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:FakeTimeSource",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:MddTestDependencies",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:log_enums_java_proto_lite",
        "//proto:logs_java_proto_lite",
        "//proto:transform_java_proto_lite",
        "@androidx_test",
        "@com_google_guava_guava",
        "@com_google_protobuf//:protobuf_lite",
        "@mockito",
        "@truth",
    ],
)

mdd_local_test(
    name = "DataFileGroupValidatorTest",
    srcs = ["DataFileGroupValidatorTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.DataFileGroupValidatorTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload/internal:DataFileGroupValidator",
        "//java/com/google/android/libraries/mobiledatadownload/internal:Migrations",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:transform_java_proto_lite",
        "@com_google_guava_guava",
        "@truth",
    ],
)

mdd_local_test(
    name = "MigrationsTest",
    srcs = ["MigrationsTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.MigrationsTest",
    deps = [
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/internal:Migrations",
        "@truth",
    ],
)

mdd_local_test(
    name = "FileGroupManagerTest",
    srcs = ["FileGroupManagerTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.FileGroupManagerTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:AccountSource",
        "//java/com/google/android/libraries/mobiledatadownload:AggregateException",
        "//java/com/google/android/libraries/mobiledatadownload:DownloadException",
        "//java/com/google/android/libraries/mobiledatadownload:ExperimentationConfig",
        "//java/com/google/android/libraries/mobiledatadownload:FileSource",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/account:AccountUtil",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends:android",
        "//java/com/google/android/libraries/mobiledatadownload/file/common",
        "//java/com/google/android/libraries/mobiledatadownload/file/spi",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:MddExceptions",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFileManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesFileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesSharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/collect",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:DownloaderCallbackImpl",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:MddFileDownloader",
        "//java/com/google/android/libraries/mobiledatadownload/internal/experimentation:DownloadStageManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal/experimentation:NoOpDownloadStageManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:DownloadStateLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging/testing:FakeEventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:DirectoryUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:FileGroupUtil",
        "//java/com/google/android/libraries/mobiledatadownload/monitor:DownloadProgressMonitor",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:FakeTimeSource",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:log_enums_java_proto_lite",
        "//proto:logs_java_proto_lite",
        "@com_google_errorprone_error_prone_annotations",
        "@com_google_guava_guava",
        "@com_google_protobuf//:any_proto",
        "@com_google_protobuf//:protobuf_lite",
        "@com_google_protobuf//:wrappers_proto",
        "@mockito",
        "@robolectric",
        "@truth",
    ],
)

mdd_local_test(
    name = "FileGroupsMetadataTest",
    srcs = ["FileGroupsMetadataTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.FileGroupsMetadataTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends:android",
        "//java/com/google/android/libraries/mobiledatadownload/file/openers:stream",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesFileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/collect",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:DirectoryUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:FileGroupUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:FileGroupsMetadataUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:ProtoConversionUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:SharedPreferencesUtil",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:FakeTimeSource",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:download_config_java_proto_lite",
        "//proto:log_enums_java_proto_lite",
        "@androidx_test",
        "@com_google_errorprone_error_prone_annotations",
        "@com_google_guava_guava",
        "@mockito",
        "@truth",
    ],
)

mdd_local_test(
    name = "ExpirationHandlerTest",
    srcs = ["ExpirationHandlerTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.ExpirationHandlerTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/delta:DeltaDecoder",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/spi",
        "//java/com/google/android/libraries/mobiledatadownload/internal:ExpirationHandler",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:Migrations",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFileManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesFileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesSharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/collect",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:MddFileDownloader",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:DirectoryUtil",
        "//java/com/google/android/libraries/mobiledatadownload/monitor:DownloadProgressMonitor",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:FakeTimeSource",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:log_enums_java_proto_lite",
        "@androidx_test",
        "@com_google_guava_guava",
        "@mockito",
        "@truth",
    ],
)

mdd_local_test(
    name = "SharedFileManagerTest",
    srcs = ["SharedFileManagerTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.SharedFileManagerTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:DownloadException",
        "//java/com/google/android/libraries/mobiledatadownload:FileSource",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/delta:DeltaDecoder",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends:android",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends:blob_uri",
        "//java/com/google/android/libraries/mobiledatadownload/file/common/testing",
        "//java/com/google/android/libraries/mobiledatadownload/file/spi",
        "//java/com/google/android/libraries/mobiledatadownload/file/transforms:compress",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:MddExceptions",
        "//java/com/google/android/libraries/mobiledatadownload/internal:Migrations",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFileManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesSharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:DeltaFileDownloaderCallbackImpl",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:DownloaderCallbackImpl",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:FileNameUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:MddFileDownloader",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:DirectoryUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:FileGroupUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:SharedPreferencesUtil",
        "//java/com/google/android/libraries/mobiledatadownload/monitor:DownloadProgressMonitor",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:log_enums_java_proto_lite",
        "//proto:logs_java_proto_lite",
        "//proto:transform_java_proto_lite",
        "@com_google_errorprone_error_prone_annotations",
        "@com_google_guava_guava",
        "@com_google_protobuf//:protobuf_lite",
        "@mockito",
        "@truth",
    ],
)

mdd_local_test(
    name = "SharedFilesMetadataTest",
    srcs = ["SharedFilesMetadataTest.java"],
    test_class = "com.google.android.libraries.mobiledatadownload.internal.SharedFilesMetadataTest",
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends:android",
        "//java/com/google/android/libraries/mobiledatadownload/file/openers:stream",
        "//java/com/google/android/libraries/mobiledatadownload/internal:Migrations",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesSharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:SharedFilesMetadataUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:SharedPreferencesUtil",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:log_enums_java_proto_lite",
        "//proto:logs_java_proto_lite",
        "//proto:transform_java_proto_lite",
        "@com_google_guava_guava",
        "@mockito",
        "@truth",
    ],
)

android_library(
    name = "MddTestUtil",
    testonly = 1,
    srcs = ["MddTestUtil.java"],
    deps = [
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//proto:download_config_java_proto_lite",
        "//proto:transform_java_proto_lite",
        "@androidx_test",
        "@com_google_android_testing//:util",
        "@com_google_errorprone_error_prone_annotations",
        "@com_google_protobuf//:protobuf_lite",
        "@truth",
        "@ub_uiautomator",
    ],
)

android_test_multi_api(
    name = "MddIsolatedStructuresTest",
    size = "large",
    srcs = ["MddIsolatedStructuresTest.java"],
    manifest = "AndroidManifest.xml",
    multidex = "native",
    target_apis = [
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
    ],
    deps = [
        ":MddTestUtil",
        "//java/com/google/android/libraries/mobiledatadownload:AggregateException",
        "//java/com/google/android/libraries/mobiledatadownload:DownloadException",
        "//java/com/google/android/libraries/mobiledatadownload:ExperimentationConfig",
        "//java/com/google/android/libraries/mobiledatadownload:Flags",
        "//java/com/google/android/libraries/mobiledatadownload:SilentFeedback",
        "//java/com/google/android/libraries/mobiledatadownload/account:AccountUtil",
        "//java/com/google/android/libraries/mobiledatadownload/file",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends",
        "//java/com/google/android/libraries/mobiledatadownload/file/backends:android",
        "//java/com/google/android/libraries/mobiledatadownload/file/common",
        "//java/com/google/android/libraries/mobiledatadownload/file/common/testing",
        "//java/com/google/android/libraries/mobiledatadownload/file/common/testing:fake_file_backend",
        "//java/com/google/android/libraries/mobiledatadownload/file/openers:bytes",
        "//java/com/google/android/libraries/mobiledatadownload/file/openers:file",
        "//java/com/google/android/libraries/mobiledatadownload/file/spi",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:FileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:MddExceptions",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFileManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesFileGroupsMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal:SharedPreferencesSharedFilesMetadata",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:DownloaderCallbackImpl",
        "//java/com/google/android/libraries/mobiledatadownload/internal/downloader:MddFileDownloader",
        "//java/com/google/android/libraries/mobiledatadownload/internal/experimentation:NoOpDownloadStageManager",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:EventLogger",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:LoggingStateStore",
        "//java/com/google/android/libraries/mobiledatadownload/internal/logging:SharedPreferencesLoggingState",
        "//java/com/google/android/libraries/mobiledatadownload/internal/proto:metadata_java_proto_lite",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:DirectoryUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:FileGroupUtil",
        "//java/com/google/android/libraries/mobiledatadownload/internal/util:SymlinkUtil",
        "//java/com/google/android/libraries/mobiledatadownload/monitor:DownloadProgressMonitor",
        "//java/com/google/android/libraries/mobiledatadownload/monitor:NetworkUsageMonitor",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:BlockingFileDownloader",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:FakeTimeSource",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:MddTestDependencies",
        "//javatests/com/google/android/libraries/mobiledatadownload/testing:TestFlags",
        "//proto:log_enums_java_proto_lite",
        "//proto:logs_java_proto_lite",
        "//proto:transform_java_proto_lite",
        "@android_sdk_linux",
        "@androidx_test",
        "@com_google_guava_guava",
        "@com_google_protobuf//:any_proto",
        "@com_google_protobuf//:protobuf_lite",
        "@com_google_protobuf//:wrappers_proto",
        "@junit",
        "@mockito",
        "@truth",
    ],
)
